<!DOCTYPE html>
<html lang="en" >
<head>
  <meta charset="UTF-8">
  <title>你好, 我的宝藏</title>
  <link rel="stylesheet" href="./style.css">

</head>
<body>
<!-- partial:index.partial.html -->
<h1> 你好 我的宝藏！</h1>
<!-- partial -->
  <script  src="./script.js"></script>

  <!--背景音乐,网页打开正常播放,微信打开,需要点击一下屏幕-->
  <audio controls="controls" id="audio" autoplay="" loop="">
    <source src="http://sijiacheng.gitee.io/wuyuhan/wuyuhan.mp3" type="audio/mpeg"></source>
  </audio>
  <script>
    var audio=document.querySelector("#audio");
    //--创建页面监听，等待微信端页面加载完毕 触发音频播放
    document.addEventListener('DOMContentLoaded', function () {
      function audioAutoPlay() {
        var audio = document.getElementById('audio');
        audio.play();
        document.addEventListener("WeixinJSBridgeReady", function () {
          audio.play();
        }, false);
      }
      audioAutoPlay();
    });
    //--创建触摸监听，当浏览器打开页面时，触摸屏幕触发事件，进行音频播放
    document.addEventListener('touchstart', function () {
      function audioAutoPlay() {
        var audio = document.getElementById('audio');
        audio.play();
      }
      audioAutoPlay();
    });
  </script>

</body>
</html>
